<template>
  <div class="divisional">
    <!-- 品控分配数据页面 -->
    <div class="search_box">
      <el-row :gutter="20">
        <el-form
          :inline="true"
          :model="paramsInfo"
          class="demo-form-inline"
          ref="paramsForm"
        >
          <el-col :span="6">
            <el-form-item label="客户姓名" prop="name">
              <el-input v-model.trim="paramsInfo.name" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户证件号" prop="identificationNumber">
              <el-input
                v-model.trim="paramsInfo.identificationNumber"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
        <div align="left" style="padding-top: 4px">
          <el-button type="primary" size="small" @click="search"
            >查询</el-button
          >
          <el-button type="primary" size="small" @click="reset('paramsForm')"
            >重置</el-button
          >
        </div>
      </el-row>
    </div>

    <el-table
      v-loading="loading"
      element-loading-text="数据加载中"
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(212, 216, 206, 1)"
      :header-cell-style="{ background: 'LightYellow	', color: 'black' }"
      :data="tableData"
      style="width: 100%"
    >
      <el-table-column
        label="序号"
        type="index"
        align="center"
        :index="getIndex"
      ></el-table-column>
      <el-table-column label="批次号" prop="batchNumber"></el-table-column>
      <el-table-column label="客户姓名" prop="name"></el-table-column>
      <el-table-column
        label="证件号"
        prop="identificationNumber" :formatter="hidInfo"
      ></el-table-column>
      <el-table-column label="拨打组" prop="callRlolename"></el-table-column>
      <el-table-column label="拨打人员" prop="callPeopleName"></el-table-column>
      <el-table-column label="电话开始时间" prop="talkBegin"></el-table-column>
      <el-table-column label="电话结束时间" prop="talkEnd"></el-table-column>
      <el-table-column label="通话时间" prop="talkTime"></el-table-column>
      <el-table-column label="评估结果" prop="score"></el-table-column>
      <el-table-column label="评估备注" prop="checkResult"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="openScore(scope.row)" type="primary" size="small"
            >评分</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pageBox">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
    <el-dialog :visible.sync="showScore" title="语音评分" width="550px">
      <div class="divisional">
        <div class="search_box" style="padding: 2px 10px">
          <el-row :gutter="20">
            <el-form
              :inline="true"
              :model="scoreInfo"
              class="demo-form-inline"
              ref="scoreInfo"
              label-width="80px"
              label-position="right"
            >
              <el-col :span="24">
                <el-form-item label="录音文件">
                  <center>
                    <audio
                      src=""
                      preload="preload"
                      controls="controls"
                      ref="audio"
                    >
                      Your browser does not support the audio element.
                    </audio>
                  </center>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="评估结果" prop="score">
                  <el-select v-model="scoreInfo.score" placeholder="请选择">
                    <el-option
                      v-for="item in scoreOptions"
                      :key="item.score"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <!-- <el-form-item label="评分" prop="score">
                  <el-rate
                    style="margin-top: 10px; margin-left: 5px"
                    v-model="scoreInfo.score"
                    show-score
                    :max="10"
                  >
                  </el-rate>
                </el-form-item> -->
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" prop="checkResult">
                  <el-input
                    type="textarea"
                    placeholder="请输入内容"
                    maxlength="100"
                    show-word-limit
                    resize="none"
                    rows="3"
                    style="width: 400px !important; height: 96px !important"
                    v-model="scoreInfo.checkResult"
                  >
                  </el-input>
                </el-form-item>
              </el-col>
            </el-form>
          </el-row>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showScore = false">取 消</el-button>
        <el-button type="primary" @click="saveScore">提 交</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { cmcUrl } from "../../../../static/baseUrl";
import { Message } from "element-ui";
export default {
  data() {
    return {
      scoreOptions: [
        {
          value: "优秀录音",
          label: "优秀录音",
        },
        {
          value: "违规录音",
          label: "违规录音",
        },
        {
          value: "正常录音",
          label: "正常录音",
        },
        {
          value: "未评估录音",
          label: "未评估录音",
        },
      ],
      score: "",
      branchDisable: false,
      subBranchDisable: false,
      groups: [],
      users: [],
      paramsInfo: {
        name: "",
        identificationNumber: "",
      },
      loading: false,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
      checkedIds: "",
      showScore: false,
      scoreInfo: {
        score: 0,
        checkResult: "",
      },
    };
  },
  created() {
    this.checkInfo();
  },
  methods: {
    handleCurrentChange(data) {
      this.currentPage = data;
      this.checkInfo();
    },
    handleSizeChange(data) {
      this.pageSize = data;
      this.checkInfo();
    },
    getIndex(index) {
      index = index + 1 + (this.currentPage - 1) * this.pageSize;
      return index;
    },
    search() {
      this.currentPage = 1;
      this.checkInfo();
    },
    reset(formRef) {
      this.$refs[formRef].resetFields();
    },
    //主页面列表数据
    checkInfo() {
      this.$set(this.paramsInfo, "page", this.currentPage);
      this.$set(this.paramsInfo, "pageSize", this.pageSize);
      this.loading = true;
      this.$axios({
        method: "post",
        url: `/CMC/quaCont/scoreData`,
        data: this.paramsInfo,
      })
        .then((res) => {
          this.loading = false;
          if (res.code == 200) {
            this.tableData = res.data.list;
            this.total = Number(res.data.total);
          } else {
            console.error(res.message);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //打开评分板
    openScore(data) {
      this.scoreInfo = JSON.parse(JSON.stringify(data));
      this.showScore = true;
      let that = this;
      that.$nextTick(() => {
        that.$refs.audio.src = "https://www.w3school.com.cn//i/song.mp3";
      });
    },
    saveScore() {
      this.$axios({
        method: "post",
        url: `/CMC/quaCont/updateScore`,
        data: this.scoreInfo,
      })
        .then((res) => {
          if (res.code == 200) {
            this.$message.success("提交成功！");
          } else {
            console.error(res.message);
          }
          this.showScore = false;
          this.checkInfo();
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.divisional {
  .search_box {
    background: #fff;
    border-radius: 10px;
    padding: 40px 40px 25px 40px;
    margin: 0 0 20px 0;
  }

  .pageBox {
    display: flex;
    width: 100%;
    justify-content: left;
    margin-top: 10px;
  }

  /deep/ .el-dialog {
    .mainInfoBox {
      width: 100%;
      max-height: 60vh;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: flex-start;
      flex-wrap: wrap;
      overflow-y: auto;

      .infoBox {
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        height: 40px;
        width: 30%;

        label {
          width: 100px;

          margin-right: 5px;
        }

        .el-input {
          flex: 1 1 auto;
        }
      }
    }
  }
}
</style>
